const router = require('express').Router();
const { dbQuery, dbError, sqlStrQuotationHandle } = require('../../tools');

router.get('/group', function(req, res) {
    const {kw} = req.query;
    const kwStr = sqlStrQuotationHandle(kw);

    dbQuery(`
        select count(m.user_id) as people_num,g.group_id,g.group_name, g.group_intro, g.group_avator from
            (
                select group_id, group_name, group_intro, group_avator from group_table 
                where group_name like '%${kwStr}%' or group_id='${kwStr}'
            ) g,
            member_table m
        where m.group_id=g.group_id
        GROUP BY g.group_id
        `)
    .then(data => {
        res.send({code: 1, message: '搜索成功', data});
    })
    .catch(err => {
        dbError(res, err);
    })
});

module.exports = router;
